package org.utils.net;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;

import org.utils.io.StreamUtils;

public class UrlUtils
{
	private UrlUtils() {}

	public static void writeToFile(URL u, String filename)
		throws IOException
	{
		StreamUtils.copyStream(
			u.openStream(),
			new FileOutputStream(filename)
		);
	}

	public static void writeToFile(URL u, File f)
		throws IOException
	{
		StreamUtils.copyStream(
			u.openStream(),
			new FileOutputStream(f)
		);
	}

	public static void writeToStream(URL u, OutputStream out)
		throws IOException
	{
		StreamUtils.copyStream(u.openStream(), out);
	}
}
